const tables = [
	{
		"column_name": "_id",
		"data_type": "varchar",
		"column_comment": ""
	},
	{
		"column_name": "uid",
		"data_type": "varchar",
		"column_comment": ""
	},
	{
		"column_name": "delnoted_delmuid",
		"data_type": "varchar",
		"column_comment": "交料通知单主表UID"
	},
	{
		"column_name": "delnoted_purchanduid",
		"data_type": "varchar",
		"column_comment": "采购订单明细表UID"
	},
	{
		"column_name": "delnoted_no",
		"data_type": "int",
		"column_comment": "通知序号"
	},
	{
		"column_name": "delnoted_reqdate",
		"data_type": "bigint",
		"column_comment": "通知交期"
	},
	{
		"column_name": "delnoted_quantity",
		"data_type": "int",
		"column_comment": "通知数量"
	},
	{
		"column_name": "delnoted_urgentmat",
		"data_type": "bit",
		"column_comment": "是否急料"
	},
	{
		"column_name": "delnoted_remark",
		"data_type": "varchar",
		"column_comment": "备注"
	},
	{
		"column_name": "delnoted_enterpriseuid",
		"data_type": "varchar",
		"column_comment": "平台企业UID(企业资料UID)"
	},
	{
		"column_name": "_id",
		"data_type": "varchar",
		"column_comment": ""
	},
	{
		"column_name": "uid",
		"data_type": "varchar",
		"column_comment": ""
	},
	{
		"column_name": "delnotem_code",
		"data_type": "varchar",
		"column_comment": "交料通知单号"
	},
	{
		"column_name": "delnotem_senddate",
		"data_type": "bigint",
		"column_comment": "发出日期"
	},
	{
		"column_name": "delnotem_sendloginuid",
		"data_type": "varchar",
		"column_comment": "发出人(登录账号UID)"
	},
	{
		"column_name": "delnotem_status",
		"data_type": "varchar",
		"column_comment": "单据状态0草稿 1待确认 2已确认 3退回"
	},
	{
		"column_name": "delnotem_supplieruid",
		"data_type": "varchar",
		"column_comment": "供应商uid"
	},
	{
		"column_name": "delnotem_supplierenteruid",
		"data_type": "varchar",
		"column_comment": "供应商平台企业uid"
	},
	{
		"column_name": "delnotem_customeruid",
		"data_type": "varchar",
		"column_comment": "客户uid"
	},
	{
		"column_name": "delnotem_customerenteruid",
		"data_type": "varchar",
		"column_comment": "客户平台企业uid"
	},
	{
		"column_name": "delnotem_createloginuid",
		"data_type": "varchar",
		"column_comment": "建单人"
	},
	{
		"column_name": "delnotem_createdate",
		"data_type": "bigint",
		"column_comment": "建单时间"
	},
	{
		"column_name": "delnotem_initiator",
		"data_type": "tinyint",
		"column_comment": "单据业务发起方0供应商 1客户"
	},
	{
		"column_name": "delnotem_enterpriseuid",
		"data_type": "varchar",
		"column_comment": "平台企业uid"
	}
]
const data = {
	"code": 1,
	"msg": "查询成功",
	"data": [
		{
			"uid": "654321",
			"supp_code": "USK1245",
			"supp_name": "测试提供商",
			"supp_acceptdate": 1576119886925,
			"supp_invitestate": 0,
			"supp_joindate": 1576119886925,
			"supp_latent": 0,
			"supp_latentstatus": 2
		},
		{
			"uid": "dc68c3f1-a84a-48c3-a4be-d7b7e4cc3167",
			"supp_code": ".供应商编号。。",
			"supp_name": "b",
			"supp_acceptdate": null,
			"supp_invitestate": 0,
			"supp_joindate": null,
			"supp_latent": 0,
			"supp_latentstatus": 0
		}
	],
	"totalCount": 2
}


const M = tables.reduce((p, c) => {
	if (c.column_comment) {
		p.set(c.column_name, c)
	}
	return p;
}, new Map())


const uuid = require('uuid')

function item(parent_id, prop, type, label) {
	return {
		parent_id,
		prop,
		prop_id: uuid(),
		required: true,
		type,
		optional: [],
		label: label || '',
		note: ''
	}
}
const arr = []

function obj(parent_id, data) {
	for (const key in data) {
		if (data.hasOwnProperty(key)) {
			main(parent_id, key, data[key])
		}
	}
}

function main(parent_id, prop, data) {
	const type = typeof data
	if (type === 'object') {
		if (Array.isArray(data)) {
			const root = item(parent_id, '', 'array', '')
			arr.push(root)
			obj(root.prop_id, data[0])
		} else {
			const root = item(parent_id, '', 'object', '')
			arr.push(root)
			obj(root.prop_id, data)
		}
	} else {
		if (type === 'number') {
			arr.push(item(parent_id, prop, 'number', M.get(prop)))
		} else {
			console.log(prop, M.get(prop))
			arr.push(item(parent_id, prop, 'string', M.get(prop)))
		}
	}
}


main('root', '', data)
console.log(JSON.stringify(arr))